<template>
  <el-container class="home-container">
    <el-header>
      <div class="ml-10">
        <div class="imgBox">
          <img src="https://e.im5i.com/2021/07/29/t8bFG.png" alt="">
        </div>
        <span>后台管理系统</span>
      </div>
      <el-button class="mr-10" type="danger" @click="logout" size="mini">退出</el-button>
    </el-header>
    <el-container>
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="isCollapse = !isCollapse">|||</div>
        <el-menu
        background-color="#333744"
        text-color="#fff"
        active-text-color="#409eff"
        :unique-opened="true"
        :collapse="isCollapse"
        :collapse-transition="false"
        :router="true"
        :default-active="activePath">
          <el-menu-item index="/Welcome" @click="saveNavState('/Welcome')">
            <i class="el-icon-monitor"></i>
            <template slot="title">
              <span>收银台</span>
            </template>
          </el-menu-item>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>店铺信息</span>
            </template>
            <el-menu-item index="/vip" @click="saveNavState('/vip')">
              <template slot="title">
                <i class="el-icon-bank-card"></i>
                <span>VIP列表</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/shop" @click="saveNavState('/shop')">
              <template slot="title">
                <i class="el-icon-shopping-bag-2"></i>
                <span>商品列表</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/order" @click="saveNavState('/order')">
              <template slot="title">
                <i class="el-icon-setting"></i>
                <span>订单列表</span>
              </template>
            </el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-s-custom"></i>
              <span>用户中心</span>
            </template>
            <el-menu-item index="/userInfo" @click="saveNavState('/userInfo')">
              <template slot="title">
                <i class="el-icon-user"></i>
                <span>用户信息</span>
              </template>
            </el-menu-item>
            <el-menu-item index="/users" @click="saveNavState('/users')">
              <template slot="title">
                <i class="el-icon-setting"></i>
                <span>用户管理</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      //   是否折叠
      isCollapse: false,
      //   被激活的链接地址
      activePath: ''
    }
  },
  created() {
    console.log(window.location)
    this.activePath = sessionStorage.getItem('activePath') || '/Welcome'
    // if (window.location.pathname !== this.activePath) window.location.href = window.location.origin + '#' + this.activePath // 根据 activePath 重定位页面
  },
  mounted() {},
  methods: {
    logout() {
      this.$store.commit('setUserToken', null)
      window.sessionStorage.setItem('activePath', null)
      this.$router.push('/Login')
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style scoped lang="less">
.home-container {
  height: 100%;//
  background: url(https://s.im5i.com/2021/03/09/qyOeW.webp) no-repeat;
}
.el-header {
  background-color: rgba(0,0,0,.35);
  display: flex;
  justify-content: space-between;
  padding: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
  div {
    display: flex;
    align-items: center;
    .imgBox {
      height: 60px;
      img {
        height:100%;
      }
    }
    span {
      margin-left: 10px;
    }
  }
}
.el-aside {
  // background: url(../assets/aside.png) no-repeat;
  background-size: 100%;
  .el-menu {
    border-right: none;
    opacity: 0.7;
  }
  .el-menu-item,
  /deep/.el-submenu__title {
    font-size: 12px;
    height: 40px;
    line-height: 40px;
  }
  .toggle-button {
    background-color: #4a5064;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
    opacity: 0.7;
  }
}
.el-main {
  // background-color: #eaedf1;
  height: 100%;
  min-width: 800px;
}
</style>
